00001
00002 Timeline::Timeline()
00003 {
00004 timelineNode = new osg::Group;
00005 quadGroup = new osg::Group;
00006 numOfPoints = 200;
00007 numOfIntervals = 100;
00008 vertices = new osg::Vec3Array(numOfPoints);
00009 timelineNode->addChild( createScalarBar());
00010 timelineNode->addChild( createLines());
00011 timelineNode->addChild( createQuads().get());
00012 }
00013
00014 osg::Node* Timeline::createScalarBar()
00015 {
00016 std::vector<osg::Vec4> cs;
00017 cs.push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
00018 ColorRange* cr = new ColorRange(0.0f,1.0f,cs);
00019 ScalarBar* sb = new ScalarBar(1, 21, cr, "", ScalarBar::VERTICAL, 0.1f, new MyScalarPrinter);
00020 sb->setPosition(osg::Vec3(0.0f,0.0f,0.0f));
00021 osgSim::ScalarBar::TextProperties tp;
00022 tp._fontFile = "fonts/times.ttf";
00023 tp._characterSize=0.01;
00024 sb->setTextProperties(tp);
00025 return sb;
00026 }
00027
00028 osg::ref_ptr<osg::Group> Timeline::getQuadGroup()
00029 {
00030 return quadGroup;
00031 }
00032
00033
00034 osg::Node* Timeline::getTimelineNode()
00035 {
00036 return timelineNode;
00037 }
00038
00039 void Timeline::fillVerticesArray()
00040 {
00041 float x= 0.005;
00042 float xArtis = 0.01;
00043 float y= -0.001;
00044 float z1 = 0.0;
00045 float z2 = 0.1;
00046
00047
00048 for( int i=0;i<200;i++)
00049 {
00050 float xTmp = x + (i/2*xArtis);
00051 (*vertices)[i].set(xTmp, y, z1);
00052 (*vertices)[++i].set(xTmp, y, z2);
00053
00054 }
00055 }
00056
00057
00058 void Timeline::fillQuadsArray(int i)
00059 {
00060
00061 float x1=i*0.01 + 0.006;
00062 float x2= x1 + 0.009;
00063 float y = -0.001;
00064 float z1 = 0.0;
00065 float z2 = 0.1;
00066
00067
00068 quads[0]= osg::Vec3(x1, y, z2);
00069 quads[1]= osg::Vec3(x1, y, z1);
00070 quads[2]= osg::Vec3(x2, y, z1);
00071 quads[3]= osg::Vec3(x2, y, z2);
00072
00073 }
00074
00075 osg::ref_ptr<osg::Group> Timeline::createQuads()
00076 {
00077 osg::ref_ptr<osg::Vec4Array> shared_colors = new osg::Vec4Array;
00078 shared_colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
00079 osg::ref_ptr<osg::Vec3Array> shared_normals = new osg::Vec3Array;
00080 shared_normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f));
00081
00082 for(int i=0;i<100;i++)
00083 {
00084 osg::StateSet* stateset = new osg::StateSet();
00085
00086 stateset->setMode( GL_CULL_FACE, osg::StateAttribute::OFF );
00087 osg::Material* material = new osg::Material;
00088 material->setAmbient(osg::Material::FRONT_AND_BACK,osg::Vec4(1.0f,1.0f,1.0f,1.0f));
00089 material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0f,0.0f,0.0f,0.0f));
00090 stateset->setAttributeAndModes(material,osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE);
00091 stateset->setMode( GL_LIGHTING, osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE);
00092
00093 osg::Geode* geode = new osg::Geode();
00094 osg::Geometry* polyGeom = new osg::Geometry();
00095 fillQuadsArray(i);
00096
00097 int numQuads = sizeof(quads)/sizeof(osg::Vec3);
00098 osg::Vec3Array* points = new osg::Vec3Array(numQuads,quads);
00099
00100 polyGeom->setVertexArray(points);
00101
00102
00103 polyGeom->setColorArray(shared_colors.get());
00104 polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL);
00105
00106
00107 polyGeom->setNormalArray(shared_normals.get());
00108 polyGeom->setNormalBinding(osg::Geometry::BIND_OVERALL);
00109
00110
00111
00112 polyGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON,0,numQuads));
00113
00114 geode->addDrawable(polyGeom);
00115
00116 char buffer [33];
00117 itoa (i+1,buffer,10);
00118
00119 geode->setName(buffer);
00120 geode->setStateSet(stateset);
00121 quadGroup->addChild(geode);
00122
00123 }
00124
00125 return quadGroup;
00126
00127 }
00128
00129
00130 osg::Node* Timeline::createLines()
00131 {
00132
00133 osg::Geode* geode = new osg::Geode();
00134 {
00135
00136 osg::Geometry* linesGeom = new osg::Geometry();
00137
00138 fillVerticesArray();
00139
00140
00141 linesGeom->setVertexArray(vertices);
00142
00143 osg::Vec4Array* colors = new osg::Vec4Array;
00144 colors->push_back(osg::Vec4(0.0f,0.0f,0.0f,1.0f));
00145 linesGeom->setColorArray(colors);
00146 linesGeom->setColorBinding(osg::Geometry::BIND_OVERALL);
00147
00148
00149 osg::Vec3Array* normals = new osg::Vec3Array;
00150 normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f));
00151 linesGeom->setNormalArray(normals);
00152 linesGeom->setNormalBinding(osg::Geometry::BIND_OVERALL);
00153
00154
00155 linesGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES,0,numOfPoints));
00156 geode->setName("line");
00157
00158 geode->addDrawable(linesGeom);
00159 }
00160 return geode;
00161
00162 }